import datetime
from datetime import timedelta
from sqlalchemy.orm import Session

from app.monitor_doris.models.monitor_doris_exclude import MonitorDorisExclude
from core.logger import logger
from common.utils import CommonTimeUtils



class MonitorDorisExcludeHandler():
    """ Exclude  Handler
    """
    
    def __init__(self):
        pass
        
            
    def get_exclude_keywords(self, db: Session, service_name: str):
        # 获取服务配置的屏蔽关键字
        current_datetime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        excludes = MonitorDorisExclude.get_effective_excludes(db, service_name, current_datetime)
        if not excludes:
            logger.info(f"doris service:{service_name} excludes is 0")
            return []
                    
        exclud_keywords = [item['exclude'] for item in excludes]
        return exclud_keywords
        
    
    
def test():
    from common.database import SessionLocal
    session = SessionLocal()
    service_name = ""
    monitor_doris_exclude_handler = MonitorDorisExcludeHandler()
    result = monitor_doris_exclude_handler.get_exclude_keywords(session, service_name)
    print(result)


if __name__ == '__main__':
    test()